﻿using System.Text;
using System.Web;
using System.Web.UI;

namespace AppEszköz
{
    public class Utilities
    {
        public static string BasePath
        {
            get
            {
                string applicationPath = HttpContext.Current.Request.ApplicationPath;
                if (!applicationPath.EndsWith("/"))
                    applicationPath += "/";
                return applicationPath;
            }
        }

        public static void SetInitialFocus(Control vControl)
        {
            if (vControl.Page == null)
                return;
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.Append("<SCRIPT FOR=\"window\" EVENT=\"onload\" LANGUAGE=\"JavaScript\">\n");
            stringBuilder.Append("<!--\n");
            stringBuilder.Append("\tif (document.getElementById(\"" + vControl.ClientID + "\") != null)\n");
            stringBuilder.Append("\t{\n");
            stringBuilder.Append("\t\tif (document.getElementById(\"" + vControl.ClientID + "\").disabled != true)\n");
            stringBuilder.Append("\t\t{\n");
            stringBuilder.Append("\t\t\tdocument.getElementById(\"" + vControl.ClientID + "\").focus();\n");
            stringBuilder.Append("\t\t}\n");
            stringBuilder.Append("\t}\n");
            stringBuilder.Append("//-->\n");
            stringBuilder.Append("</SCRIPT>");
            if (!vControl.Page.Request.Browser.JavaScript)
                return;
            vControl.Page.RegisterStartupScript("setOnLoadFocus", stringBuilder.ToString());
        }

        public static string SQLInjFix(string strDirty)
        {
            return strDirty.Replace("'", "`");
        }
    }
}
